package com.qf.service.impl;

import com.qf.mapper.StatMapper;
import com.qf.service.StatService;
import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 统计 service 类
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.service.impl
 * @Description:
 * @Date 2022/10/13 21:25
 */

@Service
public class StatServiceImpl implements StatService {

    @Autowired
    StatMapper statMapper;

    @Override
    public List<CategorySellAmts> findCategorySell() {
        return statMapper.findCategorySell();
    }

    @Override
    public List<DayStatis> findOrderDayStatis() {
//        获取一个月前的今天
        Calendar calendar = Calendar.getInstance();

        calendar.add(Calendar.MONTH,-1);

        Date date = calendar.getTime();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String format = sdf.format(date);

        return statMapper.findOrderDayStatis(format);
    }

    @Override
    public List<DayStatis> findUserDayStatis() {
        //        获取一个月前的今天
        Calendar calendar = Calendar.getInstance();

        calendar.add(Calendar.MONTH,-1);

        Date date = calendar.getTime();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String format = sdf.format(date);
        return statMapper.findUserDayStatis(format);
    }
}
